#include "PlatformProperty.h"

MAPPING_VALUE(sdb::GearLvrIndcn2, VehicleGear, VehicleGear::GEAR_UNKNOWN)
    MAPPING_ITEM(sdb::GearLvrIndcn2::ParkIndcn, VehicleGear::GEAR_PARK)
    MAPPING_ITEM(sdb::GearLvrIndcn2::RvsIndcn, VehicleGear::GEAR_REVERSE)
    MAPPING_ITEM(sdb::GearLvrIndcn2::NeutIndcn, VehicleGear::GEAR_NEUTRAL)
    MAPPING_ITEM(sdb::GearLvrIndcn2::DrvIndcn, VehicleGear::GEAR_DRIVE)
MAPPING_END

SYSTEM_READ_PROPERTY(GEAR_SELECTION, VehicleGear) {
    builder.area(VehicleArea::GLOBAL)
            .initValue([]() {
                return VehicleGear::GEAR_PARK;
            })
            .withStatusBySignals([]([[maybe_unused]] const PropertyStatus &last) {
                VHALOG.d("GEAR_SELECTION carconfig13[%d]", SIGNAL.getcarconfig13());
                if (SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_04)) {
                    return PropertyStatus::Active;
                }
                return PropertyStatus::NotActive;
            }, SignalRX::carconfig13)
            .withValueBySignals([]([[maybe_unused]] const VehicleGear &last) {
                sdb::GearLvrIndcn2 sdbGear = SIGNAL.getGearLvrIndcn();
                VHALOG.d("GEAR_SELECTION withValueBySignals sdbGear[%d]", sdbGear);
                VehicleGear signal = mappingValue(sdbGear, VehicleGear::GEAR_UNKNOWN);
                return signal;
            }, SignalRX::GearLvrIndcn);
}